[id].vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation1></HomePageNavigation1>
  6. <!-- 广告1 -->
  7. <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
  8. <!-- 资讯列表 -->
  9. <div class="newsDetail">
  10. <div class="inner">
  11. <div class="innerLeft">
  12. <!-- 面包屑导航 -->
  13. <div class="breadcrumb">
  14. <div class="inner">
  15. <span class="location">当前位置:</span>
  16. <el-breadcrumb :separator-icon="ArrowRight">
  17. <el-breadcrumb-item>
  18. <NuxtLink to="/">首页</NuxtLink>
  19. </el-breadcrumb-item>
  20. <el-breadcrumb-item v-if="parent_name != ''">
  21. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  22. </el-breadcrumb-item>
  23. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  24. </el-breadcrumb>
  25. </div>
  26. </div>
  27. <div class="LeftTop">
  28. <h1>{{ newsDetail.title }}</h1>
  29. <p>
  30. 来源: <span>{{ newsDetail.copyfrom }}</span>
  31. 作者: <span>{{ newsDetail.author }}</span>
  32. 发布时间: <span>{{ time }}</span>
  33. </p>
  34. </div>
  35. <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
  36. </div>
  37. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  38. <img :src="selectedImage" alt="Preview">
  39. </div>
  40. <!-- 免责声明: -->
  41. <div class="disclaimer" v-if="newsDetail.copyfrom == '本网'">
  42. <p>原文链接:{{ newsDetail.fromurl }}</p>
  43. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  44. </div>
  45. <div v-if="articleChoice">
  46. <!-- 投票 start ---------------------------------------->
  47. <div class="index_3_box_vote" v-if="articleChoice">
  48. <div class="voteTitle">投票区</div>
  49. <div class="inquire">
  50. <p v-if="voteList.length > 0">{{ voteList[0].survey_name }}</p>
  51. <div class="radioBox">
  52. <!--投票选项-->
  53. <div v-if="!isDisabled">
  54. <div class="radio" v-if="isRadio">
  55. <el-radio-group v-model="radio1" @change="handleRadioChange">
  56. <el-radio v-for="item in voteList" :key="item.id" :value="item.id"
  57. size="large">
  58. <span v-if="item.is_other == 0">{{ item.choice_name }}</span>
  59. <span v-else>其他</span>
  60. </el-radio>
  61. </el-radio-group>
  62. <el-input v-if="showUserChoice" v-model="userChoice" :rows="2" type="textarea"
  63. resize="none" placeholder="请输入.." />
  64. </div>
  65. <div class="checkInputBox" v-else>
  66. <el-checkbox-group v-model="check1" @change="handleCheckboxChange">
  67. <span v-for="item in voteList" :key="item.id">
  68. <span v-if="item.is_other == 0">
  69. <el-checkbox size="large" :label="item.choice_name"
  70. :value="item.id" />
  71. </span>
  72. <span v-else>
  73. <el-checkbox size="large" label="其他" :value="item.id" />
  74. </span>
  75. </span>
  76. </el-checkbox-group>
  77. <el-input v-if="showUserChoice" v-model="userChoice" :rows="2" type="textarea"
  78. resize="none" placeholder="请输入.." />
  79. </div>
  80. </div>
  81. <!--投票结果-->
  82. <div class="inquireData" v-else>
  83. <div v-for="item in websiteSurveyData.data" :key="item.id">
  84. <div class="inquireDataItem active" v-if="item.status == 1">
  85. <div class="inquireDataItemTitle">
  86. <span v-if="item.choice_name == ''">其他</span>
  87. <span v-else>{{ item.choice_name }}</span>
  88. </div>
  89. <div class="inquireDataItemNum">{{ item.results }}票</div>
  90. </div>
  91. <div class="inquireDataItem" v-else>
  92. <div class="inquireDataItemTitle">
  93. <span v-if="item.choice_name == ''">其他</span>
  94. <span v-else>{{ item.choice_name }}</span>
  95. </div>
  96. <div class="inquireDataItemNum">{{ item.results }}票</div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div class="btn">
  102. <button class="voting" @click="addWebsiteSurvey" :disabled="isDisabled"
  103. v-if="!isDisabled">投票</button>
  104. </div>
  105. </div>
  106. </div>
  107. <!-- 投票 end ---------------------------------------->
  108. </div>
  109. </div>
  110. <div class="innerRight">
  111. <!-- 热点资讯1 -->
  112. <div class="hotList1">
  113. <DetailHotNews></DetailHotNews>
  114. </div>
  115. <!-- 热点资讯2 -->
  116. <div class="hotList2">
  117. <DetailHotNews2></DetailHotNews2>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <!-- 广告2 -->
  123. <HomeAdvertising :imgurl="adImg2"></HomeAdvertising>
  124. <!-- 页面底部 -->
  125. <HomeFoot1></HomeFoot1>
  126. </template>
  127. <script setup>
  128. //1.页面依赖 start ---------------------------------------->
  129. import { onMounted } from 'vue'
  130. import { ElBreadcrumb, ElBreadcrumbItem, ElRadio, ElRadioGroup, ElCheckbox, ElCheckboxGroup, ElMessage, ElInput } from 'element-plus'
  131. import { ArrowRight } from '@element-plus/icons-vue'
  132. //1.页面依赖 end ---------------------------------------->
  133. //2.页面路径 start ---------------------------------------->
  134. const targetSegment = getRoutePath(1);
  135. let routeId;
  136. //通过导航路径反向查询导航id
  137. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  138. method: 'GET',
  139. query: {
  140. 'pinyin': targetSegment,
  141. },
  142. });
  143. if (getRouteId.code == 200) {
  144. routeId = getRouteId.data.category_id
  145. } else {
  146. console.log("错误位置:获得页面路径")
  147. }
  148. //2.页面路径 start ---------------------------------------->
  149. //3.面包屑 start ---------------------------------------->
  150. const route = useRoute();
  151. const articleId = parseInt(route.params.id); //获得该页面的id
  152. //3.1 获得父级栏目的名称、id
  153. const parent_name = ref([]);
  154. const parent_id = ref([]);
  155. const parent_pinyin = ref("");
  156. const parent_children_count = ref(0)
  157. let getParentNav = async () => {
  158. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  159. method: 'GET',
  160. query: {
  161. 'catid': routeId
  162. },
  163. });
  164. if (listData.code == 200) {
  165. parent_name.value = listData.data.alias;
  166. parent_id.value = listData.data.parent_id;
  167. parent_pinyin.value = listData.data.aLIas_pinyin;
  168. parent_children_count.value = listData.data.children_count;
  169. } else {
  170. console.log("错误位置:获取面包屑导航")
  171. }
  172. }
  173. getParentNav();
  174. //3.页面依赖 end ---------------------------------------->
  175. //4.页面数据 start ---------------------------------------->
  176. //4.1 资讯详情
  177. const newsDetail = ref({})
  178. const routeNewsTtitle = ref("");
  179. //4.2 发布日期
  180. const time = ref("");
  181. //4.3 路径
  182. const routLevelTitle = ref("");
  183. const routLevelId = ref("");
  184. //4.4 是否展示投票
  185. const articleChoice = ref(false);
  186. //4.5 获取详情
  187. async function getPageData() {
  188. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  189. method: 'GET',
  190. query: {
  191. 'articleid': articleId
  192. },
  193. });
  194. if (mkdata.code == 200) {
  195. //判断是否显示投票
  196. if (mkdata.data.is_survey == 1) {
  197. console.log("本篇文章含有投票!")
  198. articleChoice.value = true;
  199. getVoteList();
  200. }
  201. //获取内容
  202. newsDetail.value = mkdata.data;
  203. //获取路径
  204. routLevelTitle.value = newsDetail.value.cat_name;
  205. routLevelId.value = newsDetail.value.category_id;
  206. //获取发布时间
  207. time.value = newsDetail.value.updated_at.split(' ')[0];
  208. //修正标题长度
  209. if (newsDetail.value.title.length >= 20) {
  210. routeNewsTtitle.value = newsDetail.value.title.substr(0, 20) + "...";
  211. } else {
  212. routeNewsTtitle.value = newsDetail.value.title
  213. }
  214. } else {
  215. console.log("错误位置:获取详情内容")
  216. }
  217. }
  218. getPageData();
  219. //4.页面数据 end ---------------------------------------->
  220. //5.广告 start ---------------------------------------->
  221. let adImg1 = ref([]);
  222. let adImg2 = ref([]);
  223. onMounted(async () => {
  224. const { $webUrl, $CwebUrl } = useNuxtApp();
  225. //广告1
  226. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmw_detail_0001`
  227. const responseAd1 = await fetch(url, {
  228. headers: {
  229. 'Content-Type': 'application/json',
  230. 'Userurl': $CwebUrl,
  231. 'Origin': $CwebUrl
  232. }
  233. });
  234. const resultAd1 = await responseAd1.json();
  235. adImg1.value = resultAd1.data[0];
  236. //广告2
  237. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmw_detail_0002`
  238. const responseAd2 = await fetch(url2, {
  239. headers: {
  240. 'Content-Type': 'application/json',
  241. 'Userurl': $CwebUrl,
  242. 'Origin': $CwebUrl
  243. }
  244. });
  245. const resultAd2 = await responseAd2.json();
  246. adImg2.value = resultAd2.data[0];
  247. })
  248. //5.广告 end ---------------------------------------->
  249. //6.设置seo信息 start---------------------------------------->
  250. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  251. method: 'GET',
  252. query: {
  253. 'articleid': articleId
  254. },
  255. });
  256. if (setData.code == 200) {
  257. let seoTitle = setData.data.title;
  258. let seoDescription = setData.data.introduce;
  259. let seoKeywords = setData.data.keyword;
  260. let seoSuffix = setData.data.suffix;
  261. let seoName = setData.data.website_name;
  262. useSeoMeta({
  263. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  264. meta: [
  265. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  266. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  267. ]
  268. });
  269. } else {
  270. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  271. console.log("错误位置:设置详情页面SEO数据")
  272. console.log("后端错误反馈:", setData.message)
  273. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  274. }
  275. //6.设置seo信息 end---------------------------------------->
  276. //7.投票 start---------------------------------------->
  277. const radio1 = ref(''); //单选
  278. const check1 = ref([]); //多选
  279. const isDisabled = ref(false);//是否禁用提交按钮
  280. const isRadio = ref(true);//是否渲染单选
  281. const userSurId = ref('');//投票属于哪一篇文章
  282. const userChoice = ref('');//用于判断用户选择了其他选项以后,输入的值
  283. const userIsChoice = ref('');//用于判断其他选项目前是什么值
  284. const showUserChoice = ref(false);//是否显示其他输入框
  285. const websiteSurveyData = ref([]);//投票结果
  286. //7.2获得投票列表
  287. let voteList = ref([]);
  288. async function getVoteList() {
  289. const voteData = await requestHome('/web/getWebsiteSurvey', { method: 'GET', query: { 'art_id': articleId } });
  290. console.log(778899)
  291. console.log(voteData)
  292. if (voteData.code == 200) {
  293. voteList.value = voteData.data;
  294. console.log(voteList.value)
  295. //判断显示单选还是多选
  296. //survey_type 0是单选 1是多选
  297. if (voteData.data[0].survey_type == 0) {
  298. isRadio.value = true;
  299. console.log("1111")
  300. } else {
  301. isRadio.value = false;
  302. }
  303. //把最后一个的值拿出来 用于判断用户是否选择了其他
  304. for (let item of voteData.data) {
  305. //如果含有其他
  306. if (item.is_other == 1) {
  307. userIsChoice.value = item.id;
  308. }
  309. }
  310. //用户投票属于哪一篇文章
  311. userSurId.value = voteData.data[0].sur_id;
  312. } else {
  313. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  314. console.log("错误位置:首页投票")
  315. console.log("后端错误反馈:", voteData.message)
  316. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  317. }
  318. }
  319. //7.3当用户选择了选项,判断是否展示其他输入框
  320. const handleRadioChange = (value) => {
  321. if (value == userIsChoice.value) {
  322. showUserChoice.value = true;
  323. } else {
  324. showUserChoice.value = false;
  325. }
  326. }
  327. const handleCheckboxChange = (value) => {
  328. if (value.includes(userIsChoice.value)) {
  329. showUserChoice.value = true;
  330. } else {
  331. showUserChoice.value = false;
  332. }
  333. }
  334. //7.4发起投票
  335. async function addWebsiteSurvey() {
  336. //判断当前是单选还是多选
  337. console.log(isRadio.value)
  338. if (isRadio.value) {
  339. console.log("用户单选!")
  340. if (radio1.value != '') {
  341. //先判断一下是否使用了其他选项
  342. if (showUserChoice.value) {
  343. if (userChoice.value != '') {
  344. //文章id
  345. // console.log(userSurId.value)
  346. // 用户输入的值
  347. // console.log(userChoice.value)
  348. //如果使用了其他,其他的选项需要增加进去
  349. const ChoiceData = await requestHome('/web/addWebsiteSurveyOption', {
  350. method: 'GET',
  351. query: {
  352. 'sur_id': userSurId.value,//投票的新闻id
  353. 'choice_name': userChoice.value,//投票的选项id
  354. }
  355. });
  356. if (ChoiceData.code == 200) {
  357. //提交完其他选项以后,再正式发起投票
  358. const mkData = await requestHome('/web/addWebsiteSurveyVote', {
  359. method: 'GET',
  360. query: {
  361. 'sur_id': userSurId.value,
  362. 'choice_id': ChoiceData.data
  363. }
  364. });
  365. if (mkData.code == 200) {
  366. ElMessage.success('投票成功!')
  367. //把投票结果显示到页面上 禁用投票按钮
  368. isDisabled.value = true;
  369. websiteSurveyData.value = mkData.data;
  370. //遍历一下,把用户选中的那个设置status为1
  371. let data = mkData.data;
  372. //遍历一下,把用户选中的那个设置status为1
  373. for (let item of data.data) {
  374. for (let i of data.choice) {
  375. if (item.id == i) {
  376. console.log(item.id)
  377. item.status = 1;
  378. }
  379. }
  380. }
  381. websiteSurveyData.value = data;
  382. } else {
  383. ElMessage.error(mkData.message)
  384. }
  385. } else {
  386. ElMessage.error('其他投票失败!')
  387. }
  388. } else {
  389. ElMessage.error('请输入选项内容!')
  390. }
  391. } else {
  392. //如果没选择其他,直接提交选择的内容
  393. const mkData = await requestHome('/web/addWebsiteSurveyVote', {
  394. method: 'GET',
  395. query: {
  396. 'sur_id': userSurId.value,
  397. 'choice_id': radio1.value
  398. }
  399. });
  400. if (mkData.code == 200) {
  401. ElMessage.success('投票成功!')
  402. //把投票结果显示到页面上 禁用投票按钮
  403. isDisabled.value = true;
  404. let data = mkData.data;
  405. //遍历一下,把用户选中的那个设置status为1
  406. for (let item of data.data) {
  407. for (let i of data.choice) {
  408. if (item.id == i) {
  409. item.status = 1;
  410. }
  411. }
  412. }
  413. websiteSurveyData.value = data;
  414. } else {
  415. ElMessage.error('投票失败!')
  416. }
  417. }
  418. } else {
  419. ElMessage.error('请选择一个选项')
  420. }
  421. } else {
  422. console.log("多选!")
  423. //多选
  424. if (check1.value != []) {
  425. //先判断一下是否使用了其他选项
  426. if (showUserChoice.value) {
  427. if (userChoice.value != '') {
  428. //判断用户是否只选择了一个其他
  429. if (check1.value.length == 1) {
  430. const ChoiceData = await requestDataPromise('/web/addWebsiteSurveyOption', {
  431. method: 'GET',
  432. query: {
  433. 'sur_id': userSurId.value,//投票的新闻id
  434. 'choice_name': userChoice.value,//用户输入的其他选项文字
  435. }
  436. });
  437. if (ChoiceData.code == 200) {
  438. //提交完其他选项以后,再正式发起投票
  439. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  440. method: 'GET',
  441. query: {
  442. 'sur_id': userSurId.value,
  443. 'choice_id': ChoiceData.data
  444. }
  445. });
  446. if (mkData.code == 200) {
  447. ElMessage.success('投票成功!')
  448. //把投票结果显示到页面上 禁用投票按钮
  449. isDisabled.value = true;
  450. websiteSurveyData.value = mkData.data;
  451. //遍历一下,把用户选中的那个设置status为1
  452. let data = mkData.data;
  453. //遍历一下,把用户选中的那个设置status为1
  454. for (let item of data.data) {
  455. for (let i of data.choice) {
  456. if (item.id == i) {
  457. console.log(item.id)
  458. item.status = 1;
  459. }
  460. }
  461. }
  462. websiteSurveyData.value = data;
  463. } else {
  464. ElMessage.error(mkData.message)
  465. }
  466. } else {
  467. ElMessage.error('其他投票失败!')
  468. }
  469. } else {
  470. //用户选择了除了其他以外,还包括别的选项
  471. const ChoiceData = await requestDataPromise('/web/addWebsiteSurveyOption', {
  472. method: 'GET',
  473. query: {
  474. 'sur_id': userSurId.value,//投票的新闻id
  475. 'choice_name': userChoice.value,//用户输入的其他选项文字
  476. }
  477. });
  478. if (ChoiceData.code == 200) {
  479. let data = check1.value;
  480. //找到多选的数组,把其他默认值给替换掉
  481. for (let i = 0; i < data.length; i++) {
  482. if (data[i] == userIsChoice.value) {
  483. data[i] = ChoiceData.data;
  484. }
  485. }
  486. let jsonArray = JSON.stringify(data);
  487. //提交完其他选项以后,再正式发起投票
  488. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  489. method: 'GET',
  490. query: {
  491. 'sur_id': userSurId.value,
  492. 'choice_id': jsonArray
  493. }
  494. });
  495. if (mkData.code == 200) {
  496. ElMessage.success('投票成功!')
  497. //把投票结果显示到页面上 禁用投票按钮
  498. isDisabled.value = true;
  499. websiteSurveyData.value = mkData.data;
  500. //遍历一下,把用户选中的那个设置status为1
  501. let data = mkData.data;
  502. //遍历一下,把用户选中的那个设置status为1
  503. for (let item of data.data) {
  504. for (let i of data.choice) {
  505. if (item.id == i) {
  506. //console.log(item.id)
  507. item.status = 1;
  508. }
  509. }
  510. }
  511. websiteSurveyData.value = data;
  512. } else {
  513. ElMessage.error(mkData.message)
  514. }
  515. } else {
  516. ElMessage.error('其他投票失败!')
  517. }
  518. }
  519. } else {
  520. ElMessage.error('请输入选项内容!')
  521. }
  522. } else {
  523. let jsonArray = JSON.stringify(check1.value);
  524. //如果没选择其他,直接提交选择的内容
  525. const mkData = await requestDataPromise('/web/addWebsiteSurveyVote', {
  526. method: 'GET',
  527. query: {
  528. 'sur_id': userSurId.value,
  529. 'choice_id': jsonArray
  530. }
  531. });
  532. if (mkData.code == 200) {
  533. ElMessage.success('投票成功!')
  534. //把投票结果显示到页面上 禁用投票按钮
  535. isDisabled.value = true;
  536. websiteSurveyData.value = mkData.data;
  537. //遍历一下,把用户选中的那个设置status为1
  538. let data = mkData.data;
  539. //遍历一下,把用户选中的那个设置status为1
  540. for (let item of data.data) {
  541. for (let i of data.choice) {
  542. if (item.id == i) {
  543. console.log(item.id)
  544. item.status = 1;
  545. }
  546. }
  547. }
  548. websiteSurveyData.value = data;
  549. } else {
  550. ElMessage.error('投票失败!')
  551. }
  552. }
  553. } else {
  554. ElMessage.error('请选择一个选项')
  555. }
  556. }
  557. }
  558. //7.投票 end---------------------------------------->
  559. //8.页面图片放大 start---------------------------------------->
  560. const previewVisible = ref(false)
  561. const selectedImage = ref(' ')
  562. const openPreview = (event) => {
  563. if (event.target.tagName === 'IMG') {
  564. selectedImage.value = event.target.src;
  565. previewVisible.value = true;
  566. }
  567. }
  568. const closePreview = () => {
  569. previewVisible.value = false;
  570. }
  571. //8.页面图片放大 end---------------------------------------->
  572. </script>
  573. <style lang="less" scoped>
  574. @import url('@/assets/css/detail.less');
  575. </style>